// import { useState, useEffect } from 'react'
import Taro, { useRouter } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { AtCalendar  } from 'taro-ui'

const Calendar = () => {
  // 监听路由的参数
  const router = useRouter()
  
  // 选中日期
  const onSelectDate = ({ value }) => {
    setTimeout(() => {
      Taro.navigateBack({
        delta: 1,
        success() {
          Taro.eventCenter.trigger('scrollIntoView', value.start)
        }
      })
    }, 300)
  }

  return (
    <View>
      <AtCalendar
        currentDate={router.params.select}
        minDate={router.params.start || ''}
        maxDate={router.params.end || ''}
        format='YYYY-MM-DD'
        onSelectDate={onSelectDate}
      />
    </View>
  )
}

export default Calendar
